<?php
//namespace database\seeds;
use Illuminate\Database\Seeder;

class CategoryTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
//        factory(\App\Models\Category::class, 5)->create()->each(function($category){
//            $category->posts()->save(factory(\App\Models\Post::class)->make());
//        });

        $faker = Faker\Factory::create('zh_CN');
        $datas = [];
        foreach (range(1, 4) as $key => $value) {
            $datas[] = [
                'name' =>  'cate'.$faker->randomNumber() ,
                'hot' =>  $faker->randomNumber() ,
                'image' =>  $faker->url ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }
        DB::table('categories')->insert($datas);

        $category_ids= \App\Models\Category::pluck('id')->toArray();
        $categories = [];
        foreach (range(1, 3) as $key => $value) {
            $categories[] = [
                'name' =>  'cate'.$faker->randomNumber() ,
                'parent_id' => $faker->randomElement($category_ids),
                'hot' =>  $faker->randomNumber() ,
                'image' =>  $faker->url ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }
        DB::table('categories')->insert($categories);


    }
}
